import 'package:cbec_app/utils/ThemeConfig.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:msh_checkbox/msh_checkbox.dart';

/**
 * 各种款式的选择组件
 */
class BaseCheckBox extends StatefulWidget {
  ///是否选中
  bool value;

  ///复选框大小
  double size;

  ///动画时间(毫秒)
  final int time;

  ///禁用
  final bool? disable;

  ///监听选中
  final Function(bool selected)? onChange;
  BaseCheckBox({super.key, required this.value, this.size = 15, this.onChange,this.time=10, this.disable=false});

  @override
  State<BaseCheckBox> createState() => _BaseCheckBoxState();
}

class _BaseCheckBoxState extends State<BaseCheckBox> {
  @override
  Widget build(BuildContext context) {
    // return Transform.scale(
    //   scale: 0.8,
    //   child: Checkbox(
    //     value: widget.value,
    //     shape: CircleBorder(),
    //     activeColor: ThemeConfig.themeColor,
    //     side: BorderSide(color: ThemeConfig.divideColor),
    //     onChanged: (value) {
    //       setState(() {
    //         widget.value = value!;
    //       });
    //       if (widget.onChange != null) {
    //         widget.onChange!(value!);
    //       }
    //     },
    //   ),
    // );
    return MSHCheckbox(
      size: widget.size,
      style: MSHCheckboxStyle.fillFade,
      colorConfig: MSHColorConfig.fromCheckedUncheckedDisabled(
          checkedColor: ThemeConfig.themeColor),
      value: widget.value,
      duration: Duration(milliseconds:widget.time ),
      onChanged: (selected) {
         setState(() {
          if(widget.disable==true){
            widget.value = !selected;
          }else{
            widget.value = selected;
          }
        });
        if(widget.onChange!=null){
          widget.onChange!(selected);
        }
      },
    );
  }
}
